const path = require("path");
const webpack = require("webpack");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

// dll文件存放的目录
const dllPath = "dll";

module.exports = {
  entry: {
    // 需要提取的库文件
    vendor: [
      "core-js",
      "vue",
      "vue-router",
      "vuex",
      "moment",
      "lvzc-ui",
      "element-ui",
      "lodash",
      "echarts",
    ],
  },
  output: {
    path: path.join(__dirname, dllPath),
    filename: "[name]-dll.js",
    // 这会将你的 library bundle 暴露为名为[name]_[hash]的全局变量
    // 保持与 webpack.DllPlugin 插件配置中name名称一致
    library: "[name]_[hash]",
  },
  plugins: [
    // 清除之前的dll文件
    new CleanWebpackPlugin(),
    // 该插件为webpack自带插件无需单独引用
    // 设置环境变量
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify("production"),
      },
    }),
    // 该插件为webpack自带插件无需单独引用
    // manifest.json 描述动态链接库包含了哪些内容
    new webpack.DllPlugin({
      path: path.join(__dirname, dllPath, "[name]-manifest.json"),
      // 这里的name需要保持与 output.library中名称一致
      name: "[name]_[hash]",
    }),
  ],
};
